package com.source.module_kotlin_library.file

import com.source.module_kotlin_library.bean.User
import com.source.module_kotlin_library.utils.NumberUtils.int2String

fun main() {
    repeat(100) {
        println(it)
    }

    val arrayListOf = arrayListOf<Int>(1, 2, 3, 4, 5)
    for (i in arrayListOf.indices) {
        println(arrayListOf[i])
    }
    println(2.int2String())

    var state: Int = 2
    when (state) {
        1 -> {
            println("state=${state}")
        }
        2 -> {
            println("state=${state}")
        }
        3 -> {
            println("state=${state}")
        }
        else -> {
            println("state=else")
        }
    }

    val resultState = when {
        (state == 1) -> {
            state * 10
        }
        (state == 2) -> {
            state * 20
        }
        else -> {
            100
        }
    }

    println("resultState=${resultState}")

    var user = User("张三", "zh-password-123", "zh-verify-123")
    var user1 = User("李四", "li-password-123", "li-verify-123")
    var userResult = user.plus(user1)
//    var userResult = user + user1
    println(userResult.username + "," + userResult.password + "," + userResult.verifyCode)

    repeat(100) {
        println("repeat train : $it")
    }
    for (i in 0..99) {
        println("for in 0..99 $i")
    }
    for (i in 0 until 100) {
        println("for in 0 until 100 $i")
    }

    show()
    var view = View()
    view.setOnClickListener(object : View.OnClickListener {
        override fun onClick(view: View) {
            TODO("Not yet implemented")
        }
    })

    var view2 = View2()
    view2.setOnClickListener(::onclick)

    measureTime { println("Hello Kotlin") }

    var date = null
    var date2 = ""
    var resultDate: String
    resultDate = date ?: "我是null"
    println(resultDate)
    resultDate = date2 ?: "我是空“”"
    println(resultDate)


}

fun show() {
    println("输入日志111")
    println("输入日志112")
    println("输入日志113")
}

class View {
    interface OnClickListener {
        fun onClick(view: View)
    }

    fun setOnClickListener(listener: OnClickListener) {}
}

class View2 {
    fun setOnClickListener(listener: (View2) -> Unit) {}
}

fun onclick(view: View2) {}

//内联函数（这里定义的入参是一个函数）
inline fun measureTime(action: () -> Unit) {
    println(">>>>>    ")
    val start = System.currentTimeMillis()

    action()

    val end = System.currentTimeMillis()
    println("<<<< ${end - start}")
}

//扩展函数
fun Int.int2string(): String {
    return this.toString()
}
